import com.sun.deploy.ui.AppInfo;
import com.tedu.springdemo.day04.*;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class test07 {
    @Test
    public void test01()
    {
        ApplicationContext ac=new ClassPathXmlApplicationContext("beans13.xml");
        AngleBaby ab=(AngleBaby)ac.getBean("baby");
        System.out.println(ab);
        ((ClassPathXmlApplicationContext)ac).close();
    }
    @Test
    public void test02()
    {
        ApplicationContext ac=new ClassPathXmlApplicationContext("beans14.xml");
        Teacher teacher=(Teacher)ac.getBean("tr");
        System.out.println(teacher);
        Student stu=(Student)ac.getBean("student") ;
        System.out.println(stu);
        ((ClassPathXmlApplicationContext)ac).close();
    }
    @Test
    public void test03()
    {
        ApplicationContext ac=new ClassPathXmlApplicationContext("beans14.xml");
        NetConnection nc=(NetConnection)ac.getBean("nc");
        nc.load();nc.ping();nc.conn();nc.sendData();
        ((ClassPathXmlApplicationContext)ac).close();
    }
    @Test
    public void test04(){
        ApplicationContext ac=new ClassPathXmlApplicationContext("beans14.xml");
        Demo d=(Demo)ac.getBean("demo");
        System.out.println(d);
        ((ClassPathXmlApplicationContext)ac).close();
    }
    @Test
    public void test05(){
        ApplicationContext ac=
                new ClassPathXmlApplicationContext("beans14.xml");
        Person p=(Person)ac.getBean("person");
        System.out.println(p);
        Person2 p1=(Person2)ac.getBean("person2");
        System.out.println(p1);
        ((ClassPathXmlApplicationContext)ac).close();
    }

    /**
     * 注解方式：懒加载 @Lazy
     */
    @Test
    public void test6(){
        ApplicationContext ac=
                new ClassPathXmlApplicationContext("beans14.xml");
        Person2 p=(Person2)ac.getBean("person2");
        System.out.println(p);
        ((ClassPathXmlApplicationContext)ac).close();
    }
    /**
     * 初始化与销毁    @PostConstruct   @PreDestroy
     */
    @Test
    public void test06(){
        ApplicationContext ac=
                new ClassPathXmlApplicationContext("applicationContext.xml");
        UserDao ud=(UserDao)ac.getBean("userDao");
        ud.addUser();
        ud.myInit();
        ((ClassPathXmlApplicationContext)ac).close();
    }
}
